/**
 * Created by yangfan on 2016/10/21.
 */
define(["require",'config/appregister',"business/videoupload/services/httpServices","business/services/constant","videoData",
    "business/videoupload/directive/videoupload","business/videoupload/directive/videouploadfile","upfull"
],function(require,app,httpService,constant,videoData,uploadFile,libHttpServices){
    app.controller('videoUploadCtrl',function($scope,$state,$stateParams){
    	//标签
    	
    	$scope.isDetailPage = true;
        $scope.isMainpage = false;
		$scope.fileArr = [];
        $scope.isDetailPage = false;
        $scope.isMainpage = true;
        $scope.showFillInfo = true;
        $scope.i18n = videoData;
        $scope.mainData = {
            logoSrc:"them/images/gcj_big_logo.png"
        };
        $scope.showTemplate = {
            isSelectFile:false,
            isUploadFile:true,
            showFillLeftL:false
        };
        $scope.fillInfo = "您已成功上传1份文件 ， 失败0份";
        $scope.successNoticeInfo = "您已成功上传1个视频，请等待审核...";
        $scope.uploadFileName = "";
        $scope.uploadNoticeInfo = "";

        //多文件上传时用于判断文件类型
        $scope.currentFileType = "";
        $scope.goTo1=function(){
            $state.transitionTo("comIndexCtrl.resource", {}, {
                reload: false, inherit: false, notify: true
            });
            sessionStorage.ResourceTab = "3"
        }
        //文件上传参数
        $scope.videoname=function(a){
            $scope.vName = a;
        }
        $scope.guiz=function(){
        	 $state.go("footerCtrl.helpDetailCtrl",{helpId:4,helpDetailId:1})
        }
        $scope.inrs=function(a){
            $scope.intrun = a;
        }
        $scope.$on('file',function(a,b,c){
            $scope.filepath=b;
        })
        $scope.Subtitle=[];
         $scope.$on('fileAddress',function(a,b,c){
       		$scope.fileArr.push(b);
        })
        $scope.$on('typeId',function(a,b,c){
       		$scope.fileArr[b.index].type = b.id;
        })
        $scope.others=$scope.che2=true;
         $scope.mychec=1
        $scope.che1=false;
        $scope.my=function(){
            $scope.che1=!$scope.che1
            if($scope.che1){
                $scope.mychec=0
            }
        }
         
        $scope.other=function(){
            $scope.che2=!$scope.che2;
            if($scope.che2){
                $scope.mychec=1
            }
        }
        $scope.$on("uploadS",function(a,b){
            $scope.complete=b;
        	if(b<=1){
        		alert("视频上传成功")
        	}
        })
        if($stateParams.moveVideoId){
        	$scope.showTemplate.isUploadFile=false;
        	$scope.showTemplate.isSelectFile=true;
        	$scope.showFillInfoss=1;
        	 var req ={
                        type:"GET",
                        uri:"get",
                        data:{
                           videoId:$stateParams.moveVideoId
                        }
                    };
                    httpService.getSameVideo(req).success(function(response){
                        $scope.$apply(function(){
                            if(response.code== 610){
                                alert("视频审核未通过，无法进行修改")
                                $state.transitionTo("comIndexCtrl.resource", {}, {
                                    reload: false, inherit: false, notify: true
                                });
                                sessionStorage.ResourceTab = "3"
                            }else{
                                $scope.showss=1;
                                $scope.vName=$scope.name=response.data.videoInfo.videoName;
                                $scope.intrun=$scope.introduction=response.data.videoInfo.introduction;
                                if(response.data.videoInfo.copyright==0){
                                    $scope.Our=true;
                                    $scope.others=false;
                                    $scope.mychec=0;

                                }else{
                                    $scope.others=true;
                                    $scope.Our=false
                                    $scope.mychec=1;
                                }
                            }


                        })
                    });
                    
       $scope.addFile = function(){
       		 if($scope.vName==undefined || $scope.vName == ""){
                    alert("请输入视频名称")
                }else{
                	 var arr = {"videoId":$stateParams.moveVideoId,"videoName":$scope.vName,"introduction":$scope.intrun,"copyright":$scope.mychec};
                   var arr = JSON.stringify(arr);
                   var req ={
                        type:"POST",
                        uri:"updateVideo",
                        data:{
							 videoJsonStr:arr
                        }
                    };
                    httpService.postVideo(req).success(function(response){
                        $scope.$apply(function(){
                           if(response.code==0){
                                $scope.showFillInfo=false;
                           }
                        })
                    });
                }    
        };
                    
        }else{
			
        	$scope.addFile = function(){
            if($scope.complete!=1){
                alert("视频还没上传完哦，耐心等一会哦")
            }else{
                if($scope.vName==undefined || $scope.vName == ""){
                    alert("请输入视频名称")
                }else{
                   var arr = {"videoId":0,"videoName":$scope.vName,"introduction":$scope.intrun,"copyright":$scope.mychec};
                   var arr2 = JSON.stringify($scope.fileArr)
                   var arr = JSON.stringify(arr);
                   var req ={
                        type:"POST",
                        uri:"syncVideo",
                        data:{
                            cloudAddress:$scope.filepath,
                            videoJsonStr:arr,
                            jsonStr:arr2!="[]"?arr2:""
                        }
                    };
                    httpService.postVideo(req).success(function(response){
                        $scope.$apply(function(){
                           if(response.code==0){
                                $scope.showFillInfo=false;
                                
                           }
                        })
                    });
                }
            }

        };
        }
        
        $scope.src = {
            V:"them/images/V_logo.png",
            A:"them/images/A_logo.png"
        };
        $scope.editSrc = $scope.src.V;
        $scope.$on("uploadSuccess",function(){
        	$("#containes").removeClass("hidecon")
            $scope.$apply(function(){
                $scope.showTemplate.isSelectFile = true;
                $scope.showTemplate.isUploadFile = false;
            })
        })
        $scope.goTo = function(state){
            if(state == 'eng.uploadSelectFile'){
                $state.transitionTo(state, {}, {
                    reload: true, inherit: false, notify: true
                });
            }else{
                $state.go(state);
            }
        };
        $scope.goTosucc=function(){
          $state.go("videoUploadCtrl",{moveVideoId:null})
       /*   location.reload()*/
        }


    })
});

